package com.mf.all.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mf.all.entity.dto.DtoRole;
import com.mf.all.entity.req.search.user.SearchReqRole;
import com.mf.all.mapper.MapperRole;
import com.mf.all.service.ServicePermission;
import com.mf.all.service.ServiceRole;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;


@Service
public class ImplServiceRole extends ServiceImpl<MapperRole, DtoRole> implements ServiceRole {

    @Resource
    private ServicePermission servicePermission;

    /**
     * 查询条件
     */
    @Override
    public LambdaQueryWrapper<DtoRole> fillParams(SearchReqRole params) {
        LambdaQueryWrapper<DtoRole> qw = loadQw();
        qw.eq(ObjectUtils.isNotEmpty(params.getDeptId()), DtoRole::getDeptId, params.getDeptId());
        if (StringUtils.hasText(params.getKey())) {
            qw.and(q -> q.like(DtoRole::getRoleName, params.getKey())
                    .or()
                    .like(DtoRole::getRemark, params.getKey()));
        }

        return qw.orderByDesc(DtoRole::getId);
    }



    /**
     * 根据用户id查询角色列表
     */
    @Override
    public List<DtoRole> selectRolesByUserId(long userId) {
        return baseMapper.selectRolesByUserId(userId);
    }


}